<?php 
	namespace Admin\Controller;
	use Think\Controller;

	class CommentsController extends CommonController{
		public function index()
		{
			$model=D('comments');
			//总条数
			$total=$model->getCount();
			//总页数
			$page=new \Think\Page($total,2);
			$page->setConfig('header','总页数');
			$page->setConfig('prev','上一页');
			$page->setConfig('next','下一页');
			//获取当前页
			$p=$page->nowPage;
			//echo $p;
			//exit;
			$page_str=$page->show();
			$limit=$page->firstRow.','.$page->listRows;

			$list=$model->getAll($limit);
			//var_dump($list);exit;
			$this->assign('page',$page_str);
			$this->assign('p',$p);
			$this->assign('list',$list);
			$this->display();
		}

	//评论在前台是否显示
		public function check()
		{
			//接受当前页
			$p=$_GET['p'];

			$where['id']=$_GET['id'];
			$model=M('comments');
			$status=$model->where($where)->select();

			$data['status']=$status[0]['status']==0?1:0;

			$res=$model->where($where)->save($data);
			if ($res) 
			{
				$this->redirect('Comments/index',['p'=>$p]);
				return false;
			}
		}
	//超管在后台回复
		public function reply()
		{
			//var_dump($_POST);exit;
			//接受当前页
			$p=$_GET['p'];
			$where['id']=$_POST['id'];
			$data['reply']=$_POST['text']?$_POST['text']:'感谢您，好人好报!';
			$com_model=M('comments');

			$res=$com_model->where($where)->save($data);
			if ($res) 
			{
				$this->success('回复成功',U('Comments/index',['p'=>$p]),1);
				return false;
			}
		}
	}

?>